namespace DuToanT2.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class DinhMuc : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.CalculationUnit",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 150),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.DinhMuc_CongViec",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 150),
                        CalculationUnitId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.CalculationUnit", t => t.CalculationUnitId, cascadeDelete: true)
                .Index(t => t.CalculationUnitId);
            
            CreateTable(
                "dbo.DinhMuc_ThanhPhanHP",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        VatTuId = c.Int(nullable: false),
                        DinhMuc_CongViecId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.VatTu", t => t.VatTuId, cascadeDelete: true)
                .ForeignKey("dbo.DinhMuc_CongViec", t => t.DinhMuc_CongViecId, cascadeDelete: true)
                .Index(t => t.VatTuId)
                .Index(t => t.DinhMuc_CongViecId);
            
            CreateTable(
                "dbo.VatTu",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 150),
                        Classified = c.String(nullable: false, maxLength: 20),
                        CalculationUnitId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.CalculationUnit", t => t.CalculationUnitId)
                .Index(t => t.CalculationUnitId);
            
            CreateTable(
                "dbo.DinhMuc",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Value = c.Double(nullable: false),
                        DinhMuc_ThanhPhanHPId = c.Int(nullable: false),
                        DinhMuc_PhanCapId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.DinhMuc_ThanhPhanHP", t => t.DinhMuc_ThanhPhanHPId, cascadeDelete: true)
                .ForeignKey("dbo.DinhMuc_PhanCap", t => t.DinhMuc_PhanCapId, cascadeDelete: true)
                .Index(t => t.DinhMuc_ThanhPhanHPId)
                .Index(t => t.DinhMuc_PhanCapId);
            
            CreateTable(
                "dbo.DinhMuc_PhanCap",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 150),
                        Description = c.String(maxLength: 150),
                        DinhMuc_CongViecId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.DinhMuc_CongViec", t => t.DinhMuc_CongViecId)
                .Index(t => t.DinhMuc_CongViecId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.DinhMuc_PhanCap", new[] { "DinhMuc_CongViecId" });
            DropIndex("dbo.DinhMuc", new[] { "DinhMuc_PhanCapId" });
            DropIndex("dbo.DinhMuc", new[] { "DinhMuc_ThanhPhanHPId" });
            DropIndex("dbo.VatTu", new[] { "CalculationUnitId" });
            DropIndex("dbo.DinhMuc_ThanhPhanHP", new[] { "DinhMuc_CongViecId" });
            DropIndex("dbo.DinhMuc_ThanhPhanHP", new[] { "VatTuId" });
            DropIndex("dbo.DinhMuc_CongViec", new[] { "CalculationUnitId" });
            DropForeignKey("dbo.DinhMuc_PhanCap", "DinhMuc_CongViecId", "dbo.DinhMuc_CongViec");
            DropForeignKey("dbo.DinhMuc", "DinhMuc_PhanCapId", "dbo.DinhMuc_PhanCap");
            DropForeignKey("dbo.DinhMuc", "DinhMuc_ThanhPhanHPId", "dbo.DinhMuc_ThanhPhanHP");
            DropForeignKey("dbo.VatTu", "CalculationUnitId", "dbo.CalculationUnit");
            DropForeignKey("dbo.DinhMuc_ThanhPhanHP", "DinhMuc_CongViecId", "dbo.DinhMuc_CongViec");
            DropForeignKey("dbo.DinhMuc_ThanhPhanHP", "VatTuId", "dbo.VatTu");
            DropForeignKey("dbo.DinhMuc_CongViec", "CalculationUnitId", "dbo.CalculationUnit");
            DropTable("dbo.DinhMuc_PhanCap");
            DropTable("dbo.DinhMuc");
            DropTable("dbo.VatTu");
            DropTable("dbo.DinhMuc_ThanhPhanHP");
            DropTable("dbo.DinhMuc_CongViec");
            DropTable("dbo.CalculationUnit");
        }
    }
}
